package com.yuexun.beilunpatient.ui.consult.presenter.impl;

import com.yuexun.beilunpatient.ui.bean.BaseListEntity;
import com.yuexun.beilunpatient.ui.consult.bean.NewsDetailBean;
import com.yuexun.beilunpatient.ui.consult.model.IArticleModel;
import com.yuexun.beilunpatient.ui.consult.presenter.IArticleDetailPresenter;
import com.yuexun.beilunpatient.ui.consult.ui.view.IArticleDetailView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenss on 2018/10/29.
 */
public class ArticleDetailPresenter implements IArticleDetailPresenter {

    private IArticleDetailView view;
    private IArticleModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public ArticleDetailPresenter(IArticleModel model, IArticleDetailView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void inquireNewsDetailForIndex(Map<String, String> praise) {
        model.inquireNewsDetailForIndex(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseListEntity<NewsDetailBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("查询查询新闻详情失败");
                    }

                    @Override
                    public void onNext(BaseListEntity<NewsDetailBean> entity) {
                        view.inquireNewsDetailForIndex(entity);
                    }
                });
    }
}
